//
//  SHMainViewController.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/19.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit

class SHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = SHTabBar()
     
        tabBar.closure = {[weak self] in
            
//            print("按钮点击了")
            
            let composeView = SHComposeView()
            
            composeView.composeViewShow(self!)
            
            
            
//            let composeVC = SHComposeViewController()
//            
//            self.presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
            
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(SHHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(SHMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(SHDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(SHProfileViewController(), title: "我", imgName: "tabbar_profile")
    }
    

    func addChildViewController(vc: UIViewController,title: String,imgName: String) {
        
        vc.title = title;
        
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.image = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    }
   

}


